package com.itheima.health.service.impl;


import com.itheima.health.dao.OrderDao;
import com.itheima.health.pojo.Order;
import com.itheima.health.service.OrderService;
import com.itheima.health.vo.EChartsReportVo;
import com.itheima.health.vo.SetmealCountVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author 施子安
 * @version 1.0
 * @date 2023/4/27 15:45
 * @Description
 */
@Repository
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderDao orderDao;
    @Override
    public EChartsReportVo getSetmealReport() {
        EChartsReportVo reportVo = new EChartsReportVo();
        List<Map<String,Integer>> list = orderDao.getSetmealReport();
        log.info("预约订单套餐类型{}",list.get(1));
        if (Objects.isNull(list))
            return reportVo;
        //创建订单名称集合
        ArrayList<String> setmealNames = new ArrayList<>();
        //创建订单名称+数量集合
        ArrayList<SetmealCountVo> setmealCount = new ArrayList<>();
//        HashMap<String, Integer> setmealCount = new HashMap<>();
        list.forEach(item ->{
            setmealNames.add(String.valueOf(item.get("name")));
//            setmealCount.put(String.valueOf(item.get("name")),Integer.valueOf(item.get("value"))));

//            setmealCount.add(new SetmealCountVo(String.valueOf(item.get("name")),Integer.valueOf(String.valueOf(item.get("value")))));
            setmealCount.add(new SetmealCountVo(String.valueOf(item.get("name")),Integer.valueOf(item.get("value"))));
        });
        log.info("订单套餐名称：{}",setmealNames);
        log.info("订单套餐名称数量",setmealCount);
        reportVo.setSetmealNames(setmealNames);
        reportVo.setSetmealCount(setmealCount);
        return reportVo;
    }
    //根据id查询相关信息
    @Override
    public Map findById(Integer id) {
         Map map = orderDao.selectAll(id);
         if (map!=null){
             Date orderDate =(Date) map.get("orderDate");
             map.put("orderDate", new SimpleDateFormat("yyyy-MM-dd").format(orderDate));
         }
        return map;
    }
}
